// Copyright 2023 Leo <lipf160627@163.com>. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package healthy

type Module struct {
	Name  string
	Ready bool
}

var modules map[string]bool = make(map[string]bool)

// 注册模块
func Register(name string) bool {
	if _, ok := modules[name]; ok {
		return false
	}
	modules[name] = false
	return true
}

// 按模块名设置状态
func Set(name string, state bool) bool {
	if _, ok := modules[name]; ok {
		modules[name] = state
		return true
	}
	return false
}

// 所有已注册模块是否已全部就绪
func healthyIsReady() bool {
	for _, v := range modules {
		if !v {
			return false
		}
	}

	return true
}
